#include <stdio.h>
#include <regex.h>

int main(int argc, char *argv[])
{
   char* testStr;
   regex_t regState;
   regmatch_t *pmatch;

   testStr = argv[1];
   // compile the regular expression
   // use extended expression rules, ignore new lines, and
   // don't keep track of substrings
   if(regcomp(&regState, argv[2],REG_EXTENDED|REG_NEWLINE|REG_NOSUB))
   {
   	printf("The regular expression did not compile.\n");
      exit(1);
   }

   // check the expression against the string
   if(regexec(&regState, testStr, regState.re_nsub, pmatch, 0))
   	printf("The regular expression did not match the string '%s'.\n",
         testStr);
   else
   	printf("The regular expression matches the string '%s'.\n",
         testStr);

   regfree(&regState);

   return 0;
}
